/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.servlet;

import com.bionic.commands.user.CLogout;
import com.bionic.commands.user.CUserPage;
import com.bionic.commands.user.CUserUpdate;
import com.bionic.commands.user.CUserUpdateComfirm;
import com.bionic.commands.user.CommandLogin;
import com.bionic.commands.common.CommandNotFound;
import com.bionic.commands.common.ICommand;
import com.bionic.commands.account.CAccount;
import com.bionic.commands.common.CForward;
import com.bionic.commands.request.CRequest;
import com.bionic.commands.request.CRequestClose;
import com.bionic.commands.request.CRequestInsert;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Obuhov D.G.
 */
public class ControllerHelper {

    private static ControllerHelper instance = null;
    HashMap<String, ICommand> commands = new HashMap<String, ICommand>();
    
    public static ControllerHelper getInstancce() {
        if (instance == null) {
            instance = new ControllerHelper();
        }
        return instance;
    }
    
    public ControllerHelper() {
        commands.put("login", new CommandLogin());
        commands.put("cUserForm", new CUserPage());
        commands.put("cmdUserUpdate", new CUserUpdate());
        commands.put("cmdUserUpdateConfirm", new CUserUpdateComfirm());
        commands.put("cmdLogout", new CLogout());
        commands.put("cmdForward", new CForward());
        
        commands.put("cmdRequestInsert", new CRequestInsert());
        commands.put("cmdRequestByUser", new CRequest());
        commands.put("cmdRequestClose", new CRequestClose());
        

        commands.put("cmdAccounts", new CAccount());
    }

    public ICommand getCommand(HttpServletRequest request) {
        ICommand command = commands.get(request.getParameter("command"));
        if (command == null) {
            command = new CommandNotFound();
        }
        return command;
    }

}
